package org.jeecg.modules.tplus.service.impl;

import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.tplus.service.DatabaseService;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class DatabaseServiceImpl implements DatabaseService {

    @Resource
    private JdbcTemplate jdbcTemplate;

    public List<Map<String, Object>> queryFromSecondaryDatabase(String sql) {
        // 手动设置数据源为sqlserver
        DynamicDataSourceContextHolder.push("sqlserver");
        try {
            // 查询逻辑
            return jdbcTemplate.queryForList(sql);
        } finally {
            // 清除数据源设置
            DynamicDataSourceContextHolder.poll();
        }
    }

}
